Back to Creating the Circuitry
Entering Data Structures
The Data Structure Pixels is the easiest to define, so we will start with it. However, we can't edit the code (yet) as it hasn't been created. So we need to compile the circuitry to generate the files.
Select MyCircuit.cdl in the Solution Explorer Window, click the Right Mouse button to pop-up the options menu. Select Compile. The CDL translator will run and generate the code files and add them to the project. A popup dialog will appear reporting that 'Files have been added to the project. Do you wish to rebuild the solution ?'. Select NO (we havent finished yet).
Expanding the Solution Windows entries Generated Base Source, Generated Base Header, Generated Derived Source and Generated Derived Header, you will see all of the 118 files that have been generated for this circuit.
Base files must not be edited by users. They will be overwritten if the circuit is retranslated.
Derived files will only be overwritten if they have not been modified.
Any files no-longer required (eg. an object has changed name, hence files with the old name), will generate a prompt 'Do you wish these files to be deleted'.
Fortunately users rarely need to navigate all of these files. The appropriate file can be opened by double-clicking an object or selecting the Edit Code->option from the pop-up menu.
Pixels
The pixels data structure needs to hold an array of values for each cell in the grid and for each colour in the RGB map. We also need to hold a frame counter for the frame rate code.
Pixels.hpp
class Pixels : public ClpNewObject{
public:
...
// TODO: Add custom data access functions
Uns& FrameCount(){ return mFrameCount; }
Char* Values(){ return mValues; }
private:
// TODO: Add custom data member variables
Uns mFrameCount;
Char mValues[GRID_SIZE*GRID_SIZE*NUM_COLOUR_PLANES];
};
It is good practice to use private data values and public access functions. The member variable names are prefixed with the letter 'm'.
The constant NUM_COLOUR_PLANES needs to be added to the project header file
ProjectHeader.hpp
...
// TODO: Reference any additional headers or defines you need
...
// R, G, B and Alpha
#define NUM_COLOUR_PLANES 4
#endif
Band
Band is a variable sized structure holding either 1 row of data or multiple rows. Thus we need to use the dynamic data structure techniques for this class
BandRec.hpp
class BandRec : public BandRecBase
{
public:
Uns Construct( Uns NumRows )
{
Uns failed = ! Alloc( Band::Size( NumRows ) );
if ( ! failed )
Data().SetNumRows( NumRows );
return ! failed;
}
Uns Size(){ return Data().Size(); }
};
Band.hpp
class Band : public ClpNewObject
{
public:
...
Uns Initialise( Uns FrameNumber = 1 )
{
mFrameCount = FrameNumber;
memset( Values(), 0, mNumRows*GRID_SIZE*sizeof(Float) );
return TRUE;
}
// TODO: Add custom data access functions
void SetNumRows( Uns NumRows ){ mNumRows = NumRows; }
Uns GetNumRows(){ return mNumRows; }
Uns& FrameCount(){ return mFrameCount; }
Float* Values(){ return (Float*)(this+1); }
static Uns Size( Uns NumRows ){ return sizeof( Band ) + NumRows*GRID_SIZE*sizeof(Float); }
Uns Size(){ return sizeof( Band ) + mNumRows*GRID_SIZE*sizeof(Float); }
private:
// TODO: Add custom data member variables
Uns mNumRows;
Uns mFrameCount;
// Float mValues[mNumRows*GRID_SIZE];
};
Thus when we open each store for write we need to pass in the number of rows required 1 or NUM_ROWS.
ProjectHeader.hpp file
...
// TODO: Reference any additional headers or defines you need
...
// number of rows in a band, minus 2, 1 row each side
#define NUM_ROWS (GRID_SIZE/NB - 2)
#endif
Before entering the method code it is worth compiling the FDTD project, to ensure there are no errors.